/*
package com.xm.conf;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.concurrent.ListenableFutureCallback;

*/
/**
 * 回调测试//这里只是确保消息离开了生产者，不关心消息消费情况；
 *//*

@Slf4j
@Configuration
public class CallBackRabbitConfig2 implements ApplicationContextAware {

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        RabbitTemplate rabbitTemplate = applicationContext.getBean(RabbitTemplate.class);
        rabbitTemplate.setMandatory(true);

        rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
            @Override
            public void confirm(CorrelationData correlationData, boolean b, String s) {
                log.info("confirm-callback：相关数据：{}", correlationData);
                log.info("confirm-callback：确认情况：{}", b);
                log.info("confirm-callback：原因：{}", s);

                String id = correlationData.getId();
                correlationData.getFuture().addCallback(new ListenableFutureCallback<CorrelationData.Confirm>() {
                    @Override
                    public void onFailure(Throwable ex) {
                        log.warn("消息{}失败", id);
                    }

                    @Override
                    public void onSuccess(CorrelationData.Confirm result) {
                        log.warn("消息{}成功", id);
                    }
                });
            }
        });

        rabbitTemplate.setReturnsCallback(new RabbitTemplate.ReturnsCallback() {
            @Override
            public void returnedMessage(ReturnedMessage returnedMessage) {
                log.info("returns-callback：消息：{}", returnedMessage.getMessage());
                log.info("returns-callback：回应码：{}", returnedMessage.getReplyCode());
                log.info("returns-callback：回应消息：{}", returnedMessage.getReplyText());
                log.info("returns-callback：交换机：{}", returnedMessage.getExchange());
                log.info("returns-callback：路由键：{}", returnedMessage.getRoutingKey());
            }
        });
    }
}
*/
